package com.campus.marketplace.repository;

import com.campus.marketplace.entity.OperationLog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.time.LocalDateTime;
import java.util.List;

public interface OperationLogRepository extends JpaRepository<OperationLog, Long> {
    List<OperationLog> findByUserIdOrderByCreatedAtDesc(Long userId);

    List<OperationLog> findByTargetTypeAndTargetIdOrderByCreatedAtDesc(String targetType, Long targetId);

    @Query("SELECT o FROM OperationLog o WHERE o.operationType = :operationType AND o.createdAt BETWEEN :startTime AND :endTime")
    List<OperationLog> findByOperationTypeAndTimeRange(
            @Param("operationType") String operationType,
            @Param("startTime") LocalDateTime startTime,
            @Param("endTime") LocalDateTime endTime);

    @Query("SELECT COUNT(o) FROM OperationLog o WHERE o.userId = :userId AND o.operationType = :operationType")
    Long countByUserIdAndOperationType(@Param("userId") Long userId, @Param("operationType") String operationType);
}